<?php
/* SVN FILE: $Id: app_controller.php 7945 2008-12-19 02:16:01Z gwoo $ */
/**
 * Short description for file.
 *
 * This file is application-wide controller file. You can put all
 * application-wide controller-related methods here.
 *
 * PHP versions 4 and 5
 *
 * CakePHP(tm) :  Rapid Development Framework (http://www.cakephp.org)
 * Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @filesource
 * @copyright     Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
 * @link          http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
 * @package       cake
 * @subpackage    cake.app
 * @since         CakePHP(tm) v 0.2.9
 * @version       $Revision: 7945 $
 * @modifiedby    $LastChangedBy: gwoo $
 * @lastmodified  $Date: 2008-12-18 18:16:01 -0800 (Thu, 18 Dec 2008) $
 * @license       http://www.opensource.org/licenses/mit-license.php The MIT License
 */
/**
 * Short description for class.
 *
 * Add your application-wide methods in the class below, your controllers
 * will inherit them.
 *
 * @package       cake
 * @subpackage    cake.app
 */

/**
 * @property AuthComponent $Auth
 * @property AuthorizeComponent $Authorize
 * @property SessionComponent $Session
 * @property User $User
 * @property CartComponent $Cart
 */
class AppController extends Controller
{
    public $display_cart=true;
    public $components = array('Auth','Authorize','Cart');
    public $uses = array('User');
    public $helpers = array('Javascript','Form');
    public $actionMap = array();

    public function beforeFilter()
    {
        //Set Auth component
        //$this->Session->delete("cart");
        //debug($this->params);
        Security::setHash('md5');
        $this->Auth->fields = array(
            'username' => 'email',
            'password' => 'password'
        );
        $this->Auth->userScope = array('User.active' => 1);
        $this->Auth->logoutRedirect = '/';
        $this->Auth->authorize = 'controller';
        $this->Auth->autoRedirect = false;
        $this->set("is_logged",is_array($this->Auth->user()));

        if(!empty($this->params['admin']) && $this->params['admin'] ){
            $this->layout = 'admin';
        }
    }

    public function beforeRender()
    {
        $this->set("display_cart",$this->display_cart);
        $total_price=0;
        $total_count=0;
        $this->set("is_logged",is_array($this->Auth->user()));
    }

    public function isAuthorized()
    {
        $access =  $this->Authorize->isAuthorized();
        if($access){
            return true;
        }
        $this->cakeError('error403', array('url'=>$this->params['url']['url']));
        return false;
    }

    function _access($op, $params)
    {
        $op = $op[0];
        if(array_key_exists('admin', $params) && $params['admin'] == true){
            return $this->Authorize->check('administer data');
        }
        return false;

    }
}
?>